home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / begincpp.zip / #7_VER1.CPP < prev    next >
Text File  |  1990-08-03  |  565b  |  29 lines

  1. void *malloc(unsigned);
  2. int free (void *);
  3.  
  4. struct tag_name {    //tag_name is also a type in C++
  5.     int   i;
  6.     float f;
  7. };
  8.  
  9. class class_one {
  10.     tag_name t;    //implicitly declare class_one *this;
  11.   public:
  12.     class_one (int i0 = 0, float f0 = 0) { t.i = i0, t.f = f0; }
  13.     class_one *tag() { return this; }
  14. };
  15.  
  16. class class_two {
  17.   public:
  18.     class_two (unsigned size) { this = (class_two *) malloc (size); } 
  19.     ~class_two() { free (this); this = 0; }
  20. };
  21.  
  22. main() 
  23. {
  24.     class_one c1 (1, 1.1), cc1;
  25.     class_two c2 (sizeof(class_two)) ;
  26.  
  27.     cc1 = *c1.tag();
  28. }
  29.